<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="entities.SellerEntity"%>
<%
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ request.getContextPath() + "/";
%>
<HTML>
<html>
<head>
<base href="<%=basePath%>">
<title>登录--商家系统</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<link rel="stylesheet" type="text/css"
	href="<%=basePath%>_seller/css/login.css">
<script type="text/javascript" src="<%=basePath%>js/jquery.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/GlobalFunction.js"></script>
<%
	String sellerName = (String) session.getAttribute("sellerName");

	if (sellerName != null) {
		response.sendRedirect("main.jsp");
	}
%>
<script type="text/javascript">
	$(document).ready(function() {

		$('input.textBox').keydown(function() {
			if (event.keyCode == 13) {
				SellerLogin();
			}
		});

	});

	function SellerLogin() {

		var tip = $('a#LoginTip');
		var sellerName = $('#sellerName').val();
		if (sellerName == "") {
			tip.css("color", "red");
			tip.html("帐号不能为空");
			return;
		}

		var sellerpassword = $('input#password').val();
		if (sellerpassword == "") {
			tip.css("color", "red");
			tip.html("密码不能为空");
			return;
		}

		tip.attr("class", "WaitingGray");
		tip.html("登录中……");
		$.ajax({
			type : "POST",
			url : "servlet/SellerLogServlet",
			data : "sellerName=" + sellerName + "&sellerpassword="
					+ calcMD5(sellerpassword, 32),
			error : function(error) {
				var tip = $('a#LoginTip');
				tip.attr("class", "Error");
				tip.html("登录失败，请重试");
			},
			success : function(result) {
				var tip = $('a#LoginTip');
				if (result == "success") {
					//window.history.go(-1);
					window.location.reload(true);
					return;
				}
				if (result == "noSuchSeller") {//有错误
					tip.css("color", "red");
					tip.html("查无此帐号");
					return;
				}
				if (result == "failed") {
					tip.css("color", "red");
					tip.html("帐号或密码错误");
					return;
				}
				tip.css("color", "red");
				tip.html("登录失败,请刷新重试");
			}
		});
	}
</script>
</head>

<body>
	<div id=div1>
		<table id=login height="100%" cellSpacing=0 cellPadding=0 width=800
			align=center>
			<tbody>
				<tr id=main>
					<td>
						<table height="100%" cellSpacing=0 cellPadding=0 width="100%">
							<tbody>
								<tr>
									<td colSpan=4>&nbsp;</td>
								</tr>
								<tr height=30>
									<td width=380>&nbsp;</td>
									<td>&nbsp;</td>
									<td><span style="font-size: 20;color:black;">商家登录 
									</td>
									<td>&nbsp;</td>
								</tr>
								<tr height=40>
									<td rowSpan=4>&nbsp;</td>
									<td>商家名：</td>
									<td><input class="textbox" id="sellerName"
										name="sellerName">
									</td>
									<td width=120>&nbsp;</td>
								</tr>
								<tr height=40>
									<td>密 码：</td>
									<td><input class="textbox" id="password" type="password"
										name="password">
									</td>
									<td width=120>&nbsp;</td>
								</tr>
								<tr height=40>
								<tr height=40>
									<td></td>
									<td align=right><a id="LoginTip"></a> <input type="button"
										class="button" value="登录" onclick="SellerLogin()" />
									</td>
									<td width=120>&nbsp;<a href="_seller/sellerReg.jsp"
										id="reg">注册 </a></td>
								</tr>
								<tr height=110>
									<td colSpan=4>&nbsp;</td>
								</tr>
							</tbody>
						</table>
					</td>
				</tr>
				<tr id=root height=104>
					<td>&nbsp;</td>
				</tr>
				</tbodyY>
		</table>
	</div>
	<div id=div2 style="DISPLAY: none"></div>

</body>

</html>
